package listener;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;

@WebListener
public class ContextAttributeListener implements ServletContextAttributeListener{


    @Override
    public void attributeAdded(ServletContextAttributeEvent scae) {
        //context添加属性时触发执行
        ServletContext context = scae.getServletContext();
        System.out.println("context添加"+scae.getName()+"属性,属性值："+
                context.getAttribute(scae.getName()));
    }

    @Override
    public void attributeRemoved(ServletContextAttributeEvent scae) {
        //context移除属性时触发执行
        ServletContext context = scae.getServletContext();
        System.out.println("context移除"+scae.getName()+"属性,属性值："+
                context.getAttribute(scae.getName()));
    }

    @Override
    public void attributeReplaced(ServletContextAttributeEvent scae) {
        //context修改属性时触发执行
        ServletContext context = scae.getServletContext();
        System.out.println("context修改"+scae.getName()+"属性,属性值："+
                context.getAttribute(scae.getName()));
    }
}
